Skip to content

Fix read response handling and add configurable read timeout - #75

Open
AlexanderTonn wants to merge 4 commits into
Seithan:masterfrom
AlexanderTonn:master
Open

Fix read response handling and add configurable read timeout#75
AlexanderTonn wants to merge 4 commits into
Seithan:masterfrom
AlexanderTonn:master

Conversation

@AlexanderTonn

Copy link
Copy Markdown

Description

This pull request improves the read handling of the EasyNextionLibrary and makes the timeout used by the read functions configurable.

Changes

  • Improved the handling of the Nextion end-of-command sequence (0xFF 0xFF 0xFF) when reading numeric values. (see also Issue Read still 777777 #54 )
  • Adjusted the temporary byte handling used while parsing serial responses.
  • Added a configurable timeout for readNumber() and readStr().

Added the new public method:
void setReadTimeout(uint32_t timeout);

  • The default timeout remains 1000 ms, preserving the previous behavior if no custom timeout is configured.
    Replaced the different hard-coded timeout values inside readNumber() and readStr() with the configurable _readTimeout value.

Motivation

The original implementation uses several fixed timeout values of up to 1000 ms while waiting for responses from the Nextion display.

When multiple values are read sequentially, especially in applications where the MCU also has to perform other time-critical tasks, these fixed timeouts can cause unnecessary blocking.

The new setReadTimeout() method allows the application to select a timeout appropriate for its communication setup. For example:

myNex.setReadTimeout(100);

This can significantly reduce the maximum blocking time when a Nextion response is missing or invalid, while keeping the existing 1000 ms timeout as the default for backward compatibility.

Compatibility

Existing applications do not need to be modified. If setReadTimeout() is not called, the library continues to use the default timeout of 1000 ms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant